package com.tools.elk;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.IndicesClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

import java.io.IOException;

public class ElKTest {

    public static void main(String[] args) throws IOException {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200,"http"))
        );

        IndicesClient indices = client.indices();

    /*    //创建索引
        CreateIndexRequest user = new CreateIndexRequest("user");
        CreateIndexResponse indexResponse = indices.create(user, RequestOptions.DEFAULT);
        //响应状态
        boolean acknowledged = indexResponse.isAcknowledged();
        System.out.println("创建索引："+acknowledged);*/

        //查询索引
     /*   GetIndexRequest user = new GetIndexRequest("user");
        GetIndexResponse getIndexResponse = indices.get(user, RequestOptions.DEFAULT);
        System.out.println(getIndexResponse.getAliases());
        System.out.println(getIndexResponse.getMappings());
        System.out.println(getIndexResponse.getSettings());*/

        //删除索引
     /*   DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("user");
        AcknowledgedResponse delete = indices.delete(deleteIndexRequest, RequestOptions.DEFAULT);
        System.out.println("删除成功"+delete);*/


        client.close();
    }
}
